package com.hyj.serve.manage.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hyj.serve.manage.configure.common.Result;
import com.hyj.serve.manage.configure.exception.ServiceException;
import com.hyj.serve.manage.entity.HostEntity;
import com.hyj.serve.manage.entity.firewall.FirewallInfo;
import com.hyj.serve.manage.service.FirewallService;
import com.hyj.serve.manage.service.HostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author HeYuJie
 * @date 2022/6/6
 */
@RestController
@RequestMapping("/firewall/{hostId}")
public class FirewallController extends HostControllerWidget {

    @Autowired
    private FirewallService firewallService;


    @GetMapping()
    public FirewallInfo info(){
        return firewallService.getInfo();
    }
    @GetMapping("/state")
    public boolean state(boolean state){
        return firewallService.state(state);
    }
    @GetMapping("/services")
    public String[] services(){
        return firewallService.services();
    }

    @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
    public Result<?> updateRule(@RequestBody String payload){
        JSONArray jsonArray = JSONArray.parseArray(payload);
        firewallService.updateRule(jsonArray);
        return Result.ok().build();
    }

}
